<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" type="image/ico" href="/static/common/assets/favicon.ico">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Cache-Control" content="no-cache">

	  {% load static %}
	  <link rel="stylesheet" href="{% static "css/bootstrap.min.css" %}">
    <!-- <link rel="stylesheet" type="text/css" href="{% static "vendor/animate/animate.css" %}"> -->
    <link rel="stylesheet" type="text/css" href="{% static "css/ns-login.css" %}">

    <script type="text/javascript" src="{% static "js/jquery-3.5.1.slim.min.js" %}"></script>
    <script type="text/javascript" src="{% static "js/aes.js" %}"></script>

    <!-- <script src="{% static "vendor/animsition/js/animsition.min.js" %}"></script> -->
    <!-- <script src="{% static "vendor/bootstrap/js/popper.js" %}"></script> -->
    <!-- <script src="{% static "vendor/bootstrap/js/bootstrap.min.js" %}"></script> -->

    <style>
    </style>


    <script type="text/javascript">
        var netscout = {};
        netscout.nslogin = {};


        netscout.nslogin = {
            $cnfDlg:Object,  //object for the confirmation dialog
            $passwdDlg:Object,  //object for the confirmation dialog


            encryptPassword:function(){
                var displayCurrUser= document.registerform.username.value;
                var displayNewPassword= document.registerform.password.value;
                var displayConfPassword= document.registerform.displayConfPass.value;

                var continueFlag = true;
                var element = $('#errorTextRg');
                $(element).text("");


                //CURRENT PASSWORD VALIDATION
                value = $('#passwordTextRg').val();
                if(continueFlag) continueFlag = nowhitespace(value,element);
                if(continueFlag) continueFlag = minLength(value, element);
                if(continueFlag) continueFlag = maxLength(value, element);
                if(continueFlag) continueFlag = alphanumeric2(value, element);
                if(continueFlag) continueFlag = specialChars(value, element);
                if(continueFlag) continueFlag = repeatChars(value, element);
                if(continueFlag) continueFlag = casesensitive(value, element);
                if(continueFlag) continueFlag = consecutiveChars(value, element);

                //CONFIRM PASSWORD VALIDATION
                value = $('#confirmPasswordTextRg').val();
                if(continueFlag) continueFlag = nowhitespace(value,element);
                if(continueFlag) continueFlag = equalTo($('#passwordTextRg').val(), value, element);

                if(continueFlag) {
                    //alert("continueFlag "+continueFlag);
                    var theKey = "7B355CBDA832F79610543A5D4B7BA231";
                    var aesEncryptionEnabled = "true";

                    if (aesEncryptionEnabled.trim() === "false") {
                        var stheKey = theKey.substring(0,8);
                        document.registerform.password.value = $.rc4EncryptStr(displayNewPassword, stheKey );
                        document.registerform.displayConfPass.value = $.rc4EncryptStr(displayConfPassword, stheKey );
                    }
                    else {
                        var stheKey = theKey.substring(0,16);
                        var stheKey32 = stheKey + stheKey;
                        var key = CryptoJS.enc.Utf8.parse(stheKey32);
                        var iv= CryptoJS.enc.Utf8.parse('ulFAiLTrKotxpnPV');


                        // displayNewPassword
                        encrypted = CryptoJS.AES.encrypt(displayNewPassword, key, { iv: iv });
                        cipherText = encrypted.ciphertext.toString();
                        document.registerform.password.value = cipherText;

                        // displayConfPassword
                        encrypted = CryptoJS.AES.encrypt(displayConfPassword, key, { iv: iv });
                        cipherText = encrypted.ciphertext.toString();
                        document.registerform.displayConfPass.value = cipherText;
                    }

                    document.registerform.username.value = displayCurrUser;
                } else {
										$(element).removeAttr('hidden');
                    return false;
                }
            }
        };

        function nowhitespace(value, element) {
            if(/^\S+$/i.test(value)) {
                return true;
            }
            element.text("Field cannot contain white space");
            return false;
        }

        function alphanumeric2(value, element) {
            

            return true;
        }

        function checkAlphaNumeric(value) {
            if (/(^\d+$)/.test(value)) {
                return false;
            }
            if (/^[a-zA-Z]+$/.test(value)) {
                return false;
            }
            /*checkMinNumber(value);
            checkMinLowerCase(value);*/
            return true;
        }

        function checkMinNumber(value, requiredNumbers) {
            return value.replace(/[^0-9]/g, "").length >= requiredNumbers; //value.replace(/\D/g, '').length
        }

        function checkMinLowerCase(value, minRequired) {
            var count = value.length - value.replace(/[a-z]/g, '').length;
            return count >= minRequired;
        }

        function checkMinUpperCase(value, minRequired) {
            var numUpper = value.length - value.replace(/[A-Z]/g, '').length;
            return numUpper >= minRequired;
        }

        function specialChars(value, element) {
            var specialChars= false;
            var specialCharExpected = -1;
            var displayMsg = "Must contain at least "+ specialCharExpected + ' special character(s)';

            if(specialCharExpected > 0) {
                var specialCharCount = value.length - value.replace(/[^0-9a-zA-Z\s]/g, '').length;
                if(specialCharCount >= specialCharExpected) {
                    return true;
                } else {
                    $(element).text(displayMsg);
                    return false;
                }
            }
            //$(element).text("Must contain at least one [:,.#$@%^&*()+<>?;|!]_ special character");
            return true;
        }

        function casesensitive(value, element) {
            var caseSensitive=  false;
            if(caseSensitive && !(/[a-z]/.test(value) && /[A-Z]/.test(value))){
                $(element).text("Must enter at least one uppercase and lowercase letter");//"one_uppercase_one_lowercase");
                return false
            }
            return true;
        }

        function consecutiveChars(value, element) {
            var consecutiveCount = -1;
            var isConsq = true;
            if(consecutiveCount > 0){
                //isConsecutiveNumbers(value);
                isConsq = !isConsecutiveChars(value, consecutiveCount);
                if(isConsq) {
                    $(element).text("Cannot contain more than "+consecutiveCount+" consecutive character(s)");
                }
            }
            return isConsq;
        }

        function isConsecutiveChars(value, maxAllowedCount ) {
            //console.log(".....isConsecutiveChars ..........."+value);
            var valArr = [];

            var matchFound1 = false;
            var continueLoop = true;
            for (var i = 0; i <= value.length; i++) {
                valArr = [];
                for(var j = i, count=0; count < maxAllowedCount; j++, count++) {
                    valArr[count] =  value.charCodeAt(j);
                }

                //console.log("valArr : "+$.toJSON(valArr));
                if((valArr.length) >= maxAllowedCount ) {
                    for(var k = 0; k < valArr.length-1; k++) {
                        if((valArr[k+1] - valArr[k]) !== 1) {
                            //if(Math.abs(valArr[k] - valArr[k+1]) !== 1) {
                            continueLoop = false;
                            break;
                        }

                        if(k == valArr.length-2) {
                            matchFound1 = true;
                            break;
                        }
                    }
                    if(matchFound1) {
                        break;
                    }
                }
            }
            /*if (!matchFound1) { console.log("Invalid - not consecutive");}
             else console.log("valid - consecutive  ");*/
            return matchFound1;
        }

        function repeatChars (value, element) {
            var repeatCharCount = -1;
            if(repeatCharCount > 0){
                var rex = new RegExp("(.)\\1{"+repeatCharCount+",}");
            }
            var isNotRepeat = !(/(.)\1{3,}/.test(value));
            if(!isNotRepeat) $(element).text("Cannot contain more than "+repeatCharCount+" repeat character(s)");
            return isNotRepeat
        }

        function minLength(value, element) {
            var miniLength = -1;
            if(miniLength == undefined || miniLength == null || parseInt(miniLength) < 8) {
                miniLength = 8;
            } else {
                miniLength = parseInt(miniLength);
            }

            if(value.length < miniLength) {
                $(element).text("Please enter minimum "+miniLength+ " characters");
                return false;
            }
            return true;
        }

        function maxLength(value, element) {
            var maxLength = -1;
            if(maxLength == null || maxLength == null || maxLength == -1 || maxLength > 255) {
                maxLength = 255;
            }
            if(value.length > maxLength) {
                $(element).text("Please enter less than "+maxLength+" characters" );
                return false;
            }
            return true;
        }

        function equalTo(newPassword, confirmPassword, element) {
            if(newPassword != null && confirmPassword != null && newPassword === confirmPassword) {
                return true;
            } else {
                element.text("Confirm Password mismatch");
                return false;
            }
        }

    </script>
    <title>TSA Online</title>

</head>
<body class="text-center">


  <div class="limiter">
    <div class="container-login100">
      <div class="wrap-login100 p-l-50 p-r-50 p-t-40 p-b-10">

          <span class="login100-form-title p-b-32">
            TSA Online 
          </span>

          <span class="alert alert-danger " id="errorTextRg" hidden></span>
              {% if erros %}
                 {{ erros }}
              {% endif %}
          <!-- <br> -->
          <br>

        <form action="/dappx/register/" method="post" name="registerform" class="login100-form validate-form flex-sb flex-w">

						{% csrf_token %}


          <span class="txt1 p-b-11">
            Username
          </span>

          <div class="wrap-input100 validate-input m-b-12" data-validate = "Username is required">
              <input id="usernameTextRg" class="input100" type="text" name="username" maxlength="100">
              <span class="focus-input100"></span>
          </div>

          <span class="txt1 p-b-11">
            E-Mail
          </span>

          <div class="wrap-input100 validate-input m-b-12" data-validate = "Email is required">
              <input id="useremail" class="input100" type="email" name="email" maxlength="100" >
              <span class="focus-input100"></span>
          </div>

          <span class="txt1 p-b-11">
            Password
          </span>

          <div class="wrap-input100 validate-input m-b-12">
              <input id="passwordTextRg" class="input100" type="password" name="password" maxlength="100" >
              <span class="focus-input100"></span>
          </div>

          <span class="txt1 p-b-11">
            Confirm Passord
          </span>

          <div class="wrap-input100 validate-input m-b-36">
              <input id="confirmPasswordTextRg" class="input100" type="password" name="displayConfPass" maxlength="100" >
              <span class="focus-input100"></span>
          </div>



          <div class="container-login100-form-btn ">
              <input id="submitBtnRg" class="login100-form-btn" type="submit" value="Register" onclick="return netscout.nslogin.encryptPassword();">
							<a id="submitBtnRg" class="login100-form-btn m-l-130"  href="/">Login</a>
          </div>

        </form>

        <br>
            <label id="copyrightLabel" class="mt-5 mb-3 text-muted">©2020 NETSCOUT</label>

    </div>

  </div>



</body>

</html>
